<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="css/mui.min.css"/>
</head>
<body>
    <header class="mui-bar mui-bar-nav">
        <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
        <h1 class="mui-title">裁剪图片</h1>
    </header>
    <div class="mui-content" style="width: 300px;height: 400px;">
        <div class="container">
        	<img src="" id="img" style="width: 100%;height: 100%;">
        </div>
    </div>
    <ul class="mui-table-view">
            <li class="mui-table-view-cell">
                <a class="mui-navigate-right" style="text-align: center;" id="photo">
                                           拍照
                </a>
            </li>
            <li class="mui-table-view-cell">
                <a class="mui-navigate-right" style="text-align: center;" id="gallery">
                                   从手机相册中选择
                </a>
            </li>
        </ul>
    <script src="js/mui.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/jquery.min.js"></script>
    <script type="text/javascript">
    mui.init();
    var uname = localStorage.getItem('username');
    console.log(uname);
//  var cvs = document.getElementById('head-img1');
//  var ctx = cvs.getContext('2d');
  $('#photo').click(function(){
  	  getImage()
  })
   $('#gallery').click(function(){
  	  galleryImg()
  })
    function getImage() {
			mui.plusReady(function(){
	    	   //拍照功能
	    	   //1获取摄像头对象
	    	   var bc = plus.camera.getCamera(2);
	    	   //2调用摄像头对象里的方法
	    	   bc.captureImage(function(suc){
	    	   	//返回相对路径
	    	   	var suc = plus.io.convertLocalFileSystemURL(suc);
	            console.log(suc);
	           $('#img').attr('src',suc);
	    	   },function(err){
	    	   	  console.log(err.code);
	    	   	  console.log(err.message);
	    	   },{
	    	   	index:'2'
	    	   })
	        })
		}
		//从手机相册中选择
		function galleryImg(){
				 mui.plusReady(function(){
		   	   	//pick方法
			    	plus.gallery.pick(function(success){
			    	      console.log(success);
			    	     $('#img').attr('src',success);
			    	})			
			    	},function(err){
			    		console.log(err.code);
			    		console.log(err.message);
			    	},{
			    		multiple:true,
			    		maximum:1,
			    		onmaxed:function(){
			    			plus.nativeUI.alert('最多只能选择1张',function(){
			    				console.log('user pressed');
			    			},'提示','确定')
			    		},
			    		system:false
		    	});
        }
    
    </script>
</body>
</html>

